<?php
class Warehouse_Service_Area
{
	public static $typeText = array(
		"1" => "标准",
		"2" => "不良品",
		"3" => "退货区",
		"4" => "贵重区",
	);
	
	public static function getByCondition($condition,$type='*',$order, $pageSize=0, $page=1)
	{ 
		$obj=new Warehouse_Model_Area();
		$rows= $obj->getByCondition( $condition,$type,$order, $pageSize,$page);
		return ($rows);
	}

	public static function getByfield($field,$value)
	{ 
		$obj=new Warehouse_Model_Area();
		$rows= $obj->getByfield($field,$value);
		if(!empty($rows)){
			$rows=$rows->toArray();
		}
		return $rows;
	}	
	
	public static function getByWaCode($code)
	{ 
		$obj=new Warehouse_Model_Area();
		$rows= $obj->getByWaCode($code);
		if(!empty($rows)){
			$rows=$rows->toArray();
		}
		return $rows;
	}	
	
	
	public static function getById($ura_id)
	{ 
		$obj=new Warehouse_Model_Area();
		$rows=$obj->getById($ura_id);
		if(!empty($rows)){
			$rows=$rows->toArray();
		}
		return $rows;
	}
	


	public static function create($row)
	{ 
		$obj=new Warehouse_Model_Area();
		return $obj->create($row);
	}

	public static function update($row,$ura_id)
	{ 
		$obj=new Warehouse_Model_Area();
		return $obj->update($row,$ura_id);
	}	

	public static function delete($id)
	{ 
		$obj=new Warehouse_Model_Area();
		return $obj->delete($id);
	}		
	
	public function getByWarehouseId($id){
		$obj=new Warehouse_Model_Area();
		return $obj->getByWarehouseId($id);
	}

    public static function validator($val) {
        $error = array();
        $validateArr = array();
        $validateArr[] = array('name' => '分区名称', 'value' => $val['wa_name'], 'regex' => array('require', 'length[0,255]', ));
		$validateArr[] = array('name' => '仓库分区', 'value' => $val['wa_code'], 'regex' => array('require', 'length[0,255]', ));
		$validateArr[] = array('name' => '应用类型', 'value' => $val['wa_type'], 'regex' => array('require', 'integer', ));
		$validateArr[] = array('name' => '对应产品目录', 'value' => $val['poc_id'], 'regex' => array('require', 'integer', ));
        $error = Common_Service_Validator::formValidator($validateArr);
        return $error;
    }

	/**
	*获取产品目录
	*/
	public static function getProductOptionChoose($poId=1)
	{ 
		$obj=new Product_Model_ProductOptionChoose();
		return $obj->getAllByOption($poId)->toArray();
	}	
}
